import 'package:flutter/material.dart';
import 'package:flutter_ext/home/net/feed_list.dart';

class FeedPage extends StatefulWidget{

  @override
  State<StatefulWidget> createState()  => new FeedState();
  }

class FeedState extends State<FeedPage> with SingleTickerProviderStateMixin{

  TabController _controller;

  @override
  void initState() {
    super.initState();
    _controller = new TabController( vsync: this, length: _allPages.length);
  }


  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: const Text('-category-'),
        bottom: new TabBar(
            controller: _controller,
            indicatorColor: Theme.of(context).primaryColor,
            isScrollable: true,
            tabs: _allPages.map((_Page page){
              return new Tab(
                text: page.text,);
            }).toList(),),
      actions: <Widget>[
        new Padding(
          padding: const EdgeInsets.all(4.0),
          child: new IconButton(
              icon: new Icon(Icons.reorder),
              onPressed: (){}),),
        new Padding(
          padding: const EdgeInsets.all(4.0),
          child: new IconButton(
              icon: new Icon(Icons.search),
              onPressed: (){}),
        )
      ],
      ),
      body: new TabBarView(
          controller: _controller,
          children: _allPages.map((_Page page){
            return page.feedList;
          }).toList()),
      );
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }
}

class _Page{

  _Page({
    this.icon,
    this.text,
    this.feedList
  });

  final String text;
  final IconData icon;
  final FeedList feedList;

}

final List<_Page> _allPages = <_Page>[
  new _Page(text:'All',
      feedList: new FeedList(feedType:('all'))),
  new _Page(text:'Android',
      feedList: new FeedList(feedType:('Android'))),
  new _Page(text:'推荐',
      feedList: new FeedList(feedType:('瞎推荐'))),
  new _Page(text:'iOS',
      feedList: new FeedList(feedType:('iOS'))),
  new _Page(text:'前端',
      feedList: new FeedList(feedType:('前端'))),
  new _Page(text:'Explore',
      feedList: new FeedList(feedType:('拓展资源'))),
  new _Page(text:'App',
      feedList: new FeedList(feedType:('App'))),
  new _Page(text:'what\'s hot',
      feedList: new FeedList(feedType:('休息视频'))),
  new _Page(text:'More',
      feedList: new FeedList(feedType:('福利'))),

];


